package com.datoucai.controller;

import com.alibaba.fastjson.JSON;
import com.datoucai.dto.QueryReplyInfoDto;
import com.datoucai.param.BaseResult;
import com.datoucai.param.QueryReplyRequestParam;
import com.datoucai.param.ReplyInfoDto;
import com.datoucai.service.IReplyService;
import com.datoucai.utils.BaseResultUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/reply")
@Slf4j
@Api(tags = "回复模块")
public class ReplyController {

    @Autowired
    private IReplyService replyService;


    /**
     * 查询更多评论列表
     * @param param
     * @return
     */
    @RequestMapping(value = "/query/more/reply/list",method = RequestMethod.POST)
    public BaseResult<List<ReplyInfoDto>> queryMoreReplyList(@RequestBody QueryReplyRequestParam param){
        try {
            log.info("查询更多回复-controller层-queryMoreReplyList-入参:{}", JSON.toJSONString(param));
            // 参数校验
            Assert.isTrue(param!=null,"入参不能为空");
            Assert.isTrue(param.getModule()!=null,"模块不能为空");
            Assert.isTrue(StringUtils.isNotBlank(param.getResourceId()),"资源ID不能为空");
            Assert.isTrue(StringUtils.isNotBlank(param.getCommentId()),"评论ID不能为空");
            Assert.isTrue(StringUtils.isNotBlank(param.getReplyId()),"回复ID不能为空");
            Assert.isTrue(param.getReplyNum()!=null,"回复ID不能为空");

            QueryReplyInfoDto queryReplyInfoDto = new QueryReplyInfoDto();
            queryReplyInfoDto.setCommentId(Long.valueOf(param.getCommentId()));
            queryReplyInfoDto.setReplyId(Long.valueOf(param.getReplyId()));
            queryReplyInfoDto.setModule(param.getModule());
            queryReplyInfoDto.setResourceId(Long.valueOf(param.getResourceId()));
            queryReplyInfoDto.setReplyNum(param.getReplyNum());

            List<ReplyInfoDto> replyInfoDtoList = replyService.queryMoreReplyInfoList(queryReplyInfoDto);

            return BaseResultUtils.generateSuccess(replyInfoDtoList);
        }catch (Exception e){
            log.error("查询更多回复-controller层-queryMoreReplyList-异常:", e);
            return BaseResultUtils.generateFail("查询更多回复异常:"+e.getMessage());
        }
    }




}
